package com.astronomia.wheels.tree_explore;

import com.astronomia.wheels.tree_explore.tree_entity.RegionalNodesStructureEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class PanJF_Tree {

    // 假装从DB中查出来的数据
    private static final List<RegionalNodesStructureEntity> nodesStructureEntities = new ArrayList<>();


    private static void TertiaryTree(){

        /**
         * 第一步
         * 生成三个map存放在集合内使用，
         * 分别是，以上级id为分组的三级节点，以自身节点id分组的二级节点, NodeType表明该节点的节点类型，1就是一级节点，2就是二级节点，以此类推
         */
        /*
          这里需要把‘未分组’节点给去除，
         */
        Map<Long, List<RegionalNodesStructureEntity>> threeLevelMap = nodesStructureEntities.stream()
                .filter(item -> item.getNodeType() == 3 && item.getParentId() != -1L).collect(Collectors.groupingBy(RegionalNodesStructureEntity::getParentId));

        Map<Long, RegionalNodesStructureEntity> twoLevelMap = nodesStructureEntities.stream()
                .filter(item -> item.getNodeType() == 2 && item.getId() != -1L)
                .collect(Collectors.toMap(RegionalNodesStructureEntity::getId, p -> p, (p1, p2) -> p1));

        Map<Long, RegionalNodesStructureEntity> oneLevelMap = nodesStructureEntities.stream()
                .filter(item -> item.getNodeType() == 1)
                .collect(Collectors.toMap(RegionalNodesStructureEntity::getId, p -> p, (p1, p2) -> p1));

        List<RegionalNodesStructureEntity> twoLevelList = nodesStructureEntities.stream()
                .filter(item -> item.getNodeType() == 2 && item.getParentId() == null && item.getId() != -1L)
                .collect(Collectors.toList());


    }

}
